#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=2e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//

void solve()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a == 0 && c == 0) 
    {
        cout << 0 << endl;
        return ;
    }
    else if(a == 0 || c == 0) 
    {
        cout << 1 << endl;
        return ;
    }
    int t1 = a * d, t2 = b * c; // a/b == c/d <---> ad = bd
    if(t1 < t2) swap(t1, t2);
    if(t1 == t2) cout << 0 << endl;
    else if(t1 % t2 == 0) cout << 1 << endl;
    else cout << 2 << endl;
}
int main()
{
	close();
	int T; cin>>T;
	while (T--) solve();
	return 0;
}

